package com.bz.edu.info.manager.service;

import com.bz.edu.info.manager.dao.StudentDao;
import com.bz.edu.info.manager.domin.Student;

import java.util.ArrayList;

public class StudentService {
    public void addStudent(int stuNum,String name)
    {
        StudentDao studentDao = new StudentDao();
        studentDao.addStudent(stuNum,name);
    }
    public void deleteStudent(int index)
    {
        StudentDao studentDao = new StudentDao();
        studentDao.deleteStudent(index);
    }

    public int getIndex(int stuNum)
    {
        int index = -1;
        StudentDao studentDao = new StudentDao();
        ArrayList<Student> list = studentDao.getStudentArrayList();
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            int stuNumReal = stu.getStuNum();
            if(stuNum == stuNumReal)
            {
                index = i;
            }
        }
        return  index;
    }
    public void queryStudent(){
        StudentDao studentDao = new StudentDao();
        ArrayList<Student> stuList = studentDao.getStudentArrayList();
        if(stuList.size()>0) {
            for (Student student : stuList) {
                System.out.println("学生学号：" + student.getStuNum() + "学生名字：" + student.getName());
            }
        }
        else{
            System.out.println("学生系统不存在任何信息");
        }
    }
    public void updateStudent(int index,String name){
        StudentDao studentDao = new StudentDao();
        studentDao.updateStudent(index,name);
    }
}
